package com.cg.controller;

import com.cg.client.SystemClient;
import com.cg.dto.BasePageDto;
import com.cg.dto.Result;
import com.cg.entity.BaseInfo;
import com.cg.utils.TokenUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ClassName BaseInfoController
 * @Description TODO
 * @Author CG
 * @Date 2023/12/20 11:14
 **/
@RestController
@RequestMapping("/baseInfo")
public class BaseInfoController {

    @Resource
    private SystemClient systemClient;

    /**
     * 验证基础信息表code是否重复
     */
    @GetMapping("/checkBaseCode")
    public Result checkBaseCode(String baseCode){
        return systemClient.checkBaseCode(baseCode);
    }


    /**
     * 基础信息展示
     */
    @PostMapping("/baseList")
    public Result<Map<String,Object>> baseList(BasePageDto basePageDto){
        return systemClient.baseList(basePageDto);
    }


    /**
     * 创建基础信息
     */
    @PostMapping("/insertBaseInfo")
    public Result insertBaseInfo(HttpServletRequest request,BaseInfo baseInfo){
        String token = request.getHeader("token");
        Integer userId = TokenUtil.getUserIdByToken(token);
        baseInfo.setCreateUser(userId);
        return systemClient.insertBaseInfo(baseInfo);
    }


    /**
     * 修改基础信息
     */
    @PostMapping("/setBaseInfo")
    public Result setBaseInfo(BaseInfo baseInfo){
        return systemClient.setBaseInfo(baseInfo);
    }

    /**
     * 删除基础信息
     */
    @PostMapping("/removeBaseInfo")
    public Result removeBaseInfo(Integer baseInfoId){
        return systemClient.removeBaseInfo(baseInfoId);
    }
}
